package cn.itcast.service.impl;

import cn.itcast.mapper.LogMapper;
import cn.itcast.pojo.OperateLog;
import cn.itcast.pojo.PageResult;
import cn.itcast.service.LogService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LogServiceImpl implements LogService {
    @Autowired
    private LogMapper logMapper;

    @Override
    public PageResult<OperateLog> page(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<OperateLog> operateLogList = logMapper.page(page, pageSize);
        Page<OperateLog> logListPage = (Page<OperateLog>) operateLogList;


        PageResult<OperateLog> pageResult = PageResult.<OperateLog>builder().rows(logListPage.getResult())
                .total(logListPage.getTotal())
                .build();

        return pageResult;
    }
}
